package com.feicheng.house.service.impl;

import com.feicheng.house.entity.ClientVipDepositVo;
import com.feicheng.house.entity.User;
import com.feicheng.house.mapper.ClientVipDepositVoMapper;
import com.feicheng.house.result.ResultInfo;
import com.feicheng.house.service.IClientVipDepositVoService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.aspectj.weaver.patterns.ThisOrTargetAnnotationPointcut;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * VIEW 服务实现类
 * </p>
 *
 * @author feichengTech
 * @since 2021-11-06
 */
@Service
public class ClientVipDepositVoServiceImpl extends ServiceImpl<ClientVipDepositVoMapper, ClientVipDepositVo> implements IClientVipDepositVoService {

	@Override
	public ResultInfo getClientList(Integer currentPage, Integer pageSize, String searchKey) {
				// 如果没输入当前页当前页就是“1”				
				if (null == currentPage) {
					currentPage = 1;
				}
				// 如果没输入查询多少条就默认10条			
				if (null == pageSize) {
					pageSize = 10;
					
				}
				// 构建查询条件			
				QueryWrapper<ClientVipDepositVo> clientWrapper = new QueryWrapper<ClientVipDepositVo>();
				// 如果searchKey空或空字符串，就加入查询的条件中	
				clientWrapper.eq("client_delete_flag", true);
				JSONArray searchArr = JSON.parseArray(searchKey);
				if(StringUtils.hasLength((String)searchArr.get(0))) {
					clientWrapper.like("client_name", searchArr.get(0));
				}
				if(StringUtils.hasLength((String)searchArr.get(1))) {
					clientWrapper.like("phone", searchArr.get(1));
				}
				if(StringUtils.hasLength((String)searchArr.get(2))) {
					clientWrapper.like("deposit_state", searchArr.get(2));
				}
				if(searchArr.get(3) != null) {					
					if((boolean) searchArr.get(3)) {
						clientWrapper.eq("vip_delete_flag", true);
					}else {
						clientWrapper.eq("vip_delete_flag", false).or().isNull("vip_delete_flag");
					}					
				}								
				// 创建分页查询			
				IPage<ClientVipDepositVo> pageInfo = new Page<ClientVipDepositVo>(currentPage, pageSize);
				// 返回查询结果			
				return ResultInfo.success(this.page(pageInfo, clientWrapper));
	}

	@Override
	public ResultInfo getClient(Integer clientId) {
		
		return ResultInfo.success(this.getById(clientId));
	}

}
